<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>aggiungi / rimuovi campi input</title>
<script language="JavaScript" type="text/javascript">
<!--
var num=1;
function accoda(){
	if(document.createElement && document.getElementById && document.getElementsByTagName) {
		// crea elementi
		var oTr=document.createElement("TR");
		var oTd1=document.createElement("TD");
		var oTd2=document.createElement("TD");
		var oTd3=document.createElement("TD");
		var oField=document.createElement("SELECT");
		var oField1=document.createElement("SELECT");
		var oButt=document.createElement("INPUT");

		// setta attributi
		<%java.util.Vector ve=new java.util.Vector();
			ve.add("C");
			ve.add("Java");
			ve.add("Phyton");%>
		for(i=0;i<3;i++){
		oField.options[i]=new Option('',escape('<%=ve.get(0)%>'+num),false,false);
		oField.options[i].innerHTML = '<%=ve.get(0)%>';
		}
		oField1.options[0]=new Option('',escape('1'+num),false,false);
		oField1.options[0].innerHTML = '1';
		oField1.options[1]=new Option('',escape('2'+num),false,false);
		oField1.options[1].innerHTML = '2';
		oField1.options[2]=new Option('',escape('3'+num),false,false);
		oField1.options[2].innerHTML = '3';
		oField1.options[3]=new Option('',escape('4'+num),false,false);
		oField1.options[3].innerHTML = '4';
		oField1.options[4]=new Option('',escape('5'+num),false,false);
		oField1.options[4].innerHTML = '5';
//		oField.options[1].value='Phyton';
//  		oField.setAttribute("type","option");
//		oField.setAttribute("name","testo"+num);
		oButt.setAttribute("type","button");
		oButt.setAttribute("value","rimuovi");

		// setta gestore evento
		if(oButt.attachEvent) oButt.attachEvent('onclick',function(e){rimuovi(e);})
		else if(oButt.addEventListener) oButt.addEventListener('click',function(e){rimuovi(e);},false)

		// appendi al relativo padre
		oTd1.appendChild(oField);
		oTd2.appendChild(oButt);
		oTd3.appendChild(oField1);
		oTr.appendChild(oTd1);
		oTr.appendChild(oTd3);
		oTr.appendChild(oTd2)
		document.getElementById('tabella').getElementsByTagName('TBODY')[0].appendChild(oTr);

		// incrementa variabile globale
		num++
	}
}


function rimuovi(e){
	if(document.removeChild && document.getElementById && document.getElementsByTagName) {
		if(!e) e=window.event;
		var srg=(e.target)?e.target:e.srcElement;

		// risali al tr del td che contiene l' elemento che ha scatenato l' evento
		while(srg.tagName!="TR"){srg=(srg.parentNode)?srg.parentNode:srg.parentElement}

		// riferimento al tbody
		var tb=document.getElementById('tabella').getElementsByTagName('TBODY')[0];
		
		// rimuovi
		tb.removeChild(srg);
	}
}
//-->
</script>
</head>
<body>
<form name="modulo">
<input type="text" name="login"/>
<input type="button" value="accoda" onclick="accoda()" />
<table border="1" id="tabella">
<tbody>
<tr>
<td>
	<select name="parent">
		<option value="Java">Java</option>
		<option value="C">C</option>
		<option value="Phyton">Phyton</option>
	</select>
</td>
<td>
	<select name="level">
		<option value="1">1</option>
		<option value="2">2</option>
		<option value="3">3</option>
		<option value="4">4</option>
		<option value="5">5</option>
	</select>
</td>
<td><input type="button" disabled="disabled" value="rimuovi" /></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

